import { callSequence } from "./libs/utils/function-call-seq";
import { initBundle } from "./main-menu-callback/init-bundle";
import { initFileUIManagerConfig } from "./main-menu-callback/init-config";
import { initFileCoreBase } from "./main-menu-callback/init-core-base";
import { initFileCoreManager } from "./main-menu-callback/init-core-manager";
import { initFileCoreNetwork } from "./main-menu-callback/init-core-network";
import { initFileOtherFindPathAStart } from "./main-menu-callback/init-other-find-path-astar";
import { initFileOtherFindPathNote } from "./main-menu-callback/init-other-find-path-note";
import { initFileOtherStateMachine } from "./main-menu-callback/init-other-state-machine";
import { initFilePlatformAD } from "./main-menu-callback/init-platform-ad";
import { initFilePlatformBase } from "./main-menu-callback/init-platform-base";
import { initFilePlatformGameRecommend } from "./main-menu-callback/init-platform-game-recommend";
import { initFilePluginCryptoJS, initFilePluginProtobuf, initFilePluginSocketIO } from "./main-menu-callback/init-plugin";
import { initFileUIComponent } from "./main-menu-callback/init-ui-component";
import { importI18n } from "./main-menu-callback/init-ui-i18n";
import { initFileUIManager, initFileUIManagerMachine, newUIPanel } from "./main-menu-callback/init-ui-manager";
import { initFileUITransition } from "./main-menu-callback/init-ui-transition";




// 输入标记，用于判断开发者输入之后触发的操作
let inputTag = '';

/**
 * @en Registration method for the main process of Extension
 * @zh 为扩展的主进程的注册方法
 */
export const methods: { [key: string]: (...any: any) => any } = {
    "open-panel": ()=>{
        Editor.Panel.open('tool-box-3x');
    },

    "new-assets-bundle": ()=>{
        console.log('call menu message: ', "new-assets-bundle");
        inputTag = 'new-assets-bundle';
        Editor.Panel.open('tool-box-3x');
    },
    "show-new-ui-panel": ()=>{
        console.log('call menu message: ', "show-new-ui-panel");
        inputTag = 'show-new-ui-panel';
        Editor.Panel.open('tool-box-3x');
    },
    "input-callback": (inputText)=>{
        console.log('call message: ', "input-callback");
        console.log('[tool-box]input:', inputText, inputTag);
        if (inputText === '' || inputText === undefined || inputText === null) {return;}
        
        switch (inputTag) {
            case 'new-assets-bundle': initBundle(inputText); break;
            case 'show-new-ui-panel': newUIPanel(inputText); break;
        
            default: break;
        }
        Editor.Panel.close('tool-box-3x');
    },

    "init-gamemanager": ()=>{ return callSequence([initFileUIManagerConfig, initFileUIManagerMachine, initFileCoreBase.bind(()=>{}, 'GGDevice'), initFileCoreManager.bind(() => {}, 'GGGameManager')]); },
    "init-debugmanager": ()=>{ return initFileCoreManager('GGDebugManager'); },
    "init-gganalysis": ()=>{ return initFileCoreBase('GGAnalysis'); },
    "init-ggarray": ()=>{ return initFileCoreBase('GGArray'); },
    // "init-ggaudio": ()=>{ return initFileCoreBase('GGStore', initFileCoreBase.bind(()=>{}, 'GGAudio')); },
    // "init-ggcollision2d": ()=>{ return initFileCoreBase('GGCollision2D'); },
    "init-ggcolor": ()=>{ return initFileCoreBase('GGColor'); },
    "init-ggdatetime": ()=>{ return initFileCoreBase('GGDateTime'); },
    "init-ggdatetimeformat": ()=>{ return initFileCoreBase('GGDateTimeFormat'); },
    "init-ggdevice": ()=>{ return initFileCoreBase('GGDevice'); },
    "init-ggfilesystem": ()=>{ return initFileCoreBase('GGFileSystem'); },
    "init-gglerp": ()=>{ return initFileCoreBase('GGLerp'); },
    "init-ggmath": ()=>{ return initFileCoreBase('GGMath'); },
    "init-ggnumberformat": ()=>{ return initFileCoreBase('GGNumberFormat'); },
    // "init-ggphysics2d": ()=>{ return initFileCoreBase('GGPhysics2D'); },
    "init-ggrandom": ()=>{ return initFileCoreBase('GGRandom'); },
    "init-ggresource": ()=>{ return initFileCoreBase('GGResource'); },
    "init-ggstore": ()=>{ return initFileCoreBase('GGStore'); },
    "init-ggstring": ()=>{ return initFileCoreBase('GGString'); },
    // "init-ggsystem": ()=>{ return initFileCoreBase('GGSystem'); },

    "init-ggcryptojs": ()=>{ return initFilePluginCryptoJS(initFileCoreNetwork.bind(()=>{}, 'GGCryptoJS')); },
    "init-ggnethttp": ()=>{ return initFileCoreNetwork('GGNetHTTP'); },
    "init-ggnethttpasync": ()=>{ return initFileCoreNetwork('GGNetHTTPAsync'); },
    "init-ggnetsocket": ()=>{ return initFilePluginSocketIO(initFileCoreNetwork.bind(()=>{}, 'GGNetSocket')); },
    "init-ggneturl": ()=>{ return initFileCoreNetwork('GGNetURL'); },
    "init-ggprotobuf": ()=>{ return initFilePluginProtobuf(initFileCoreNetwork.bind(()=>{}, 'GGProtobuf')); },
    "init-ggwebsocket": ()=>{ return initFileCoreNetwork('GGWebSocket'); },

    "init-file-other-findpathastart": ()=>{ return initFileOtherFindPathAStart(); },
    "init-file-other-findpathnote": ()=>{ return initFileOtherFindPathNote(); },
    "init-file-other-statemachine": ()=>{ return initFileOtherStateMachine(); },

    "init-file-flplatformlogin": ()=>{ return callSequence([initFileCoreBase.bind(()=>{}, 'GGStore'), initFileCoreBase.bind(()=>{}, 'GGDateTime'), initFilePlatformBase.bind(()=>{}, 'Login')]); },
    "init-file-flplatformserverconfig": ()=>{ return initFilePlatformBase('ServerConfig'); },
    "init-file-flplatformshare": ()=>{ return callSequence([initFileCoreBase.bind(()=>{}, 'GGStore'), initFilePlatformBase.bind(()=>{}, 'GameShare')]); },
    "init-file-flplatformappboxad": ()=>{ return initFilePlatformAD('ADAppBox'); },
    "init-file-flplatformbannerad": ()=>{ return callSequence([initFileCoreBase.bind(()=>{}, 'GGStore'), initFilePlatformAD.bind(()=>{}, 'ADBanner')]); },
    "init-file-flplatformbanneradupdate": ()=>{ return callSequence([initFilePlatformAD.bind(()=>{}, 'ADBannerUpdate')]); },
    "init-file-flplatforminterstitialad": ()=>{ return initFilePlatformAD('ADInterstitial'); },
    "init-file-flplatformnativead": ()=>{ return initFilePlatformAD('ADNative'); },
    "init-file-flplatformrewardvideoad": ()=>{ return callSequence([initFileCoreBase.bind(()=>{}, 'GGStore'), initFilePlatformAD.bind(()=>{}, 'ADRewardedVideo')]); },
    "init-file-floperatejumpupcontrol": ()=>{
        return callSequence([
            initFileCoreBase.bind(() => {}, 'GGStore'),
            initFileCoreNetwork.bind(() => {}, 'GGNetHTTPAsync'), initFilePlatformAD.bind(() => {}, 'ADBanner'),
            initFilePlatformAD.bind(() => {}, 'OperateJumpUpControl'),
        ]);

    },
    // "init-file-flplatformrecommendicon": ()=>{ return initFilePlatformGameRecommend(); },

    "init-file-uimanager": ()=>{ return initFileUIManager(); },
    "init-file-uimanagermachine": ()=>{ return initFileUIManagerMachine(); },
    // "init-ggaudioswitch": ()=>{ return initFileCoreBase('GGAudio', initFileUIComponent.bind(()=>{}, 'GGAudioSwitch')); },
    "init-ggbutton": ()=>{ return initFileUIComponent('UIButton'); },
    "init-ggdialog": ()=>{ return initFileCoreBase('GGResource', initFileUIComponent.bind(()=>{}, 'UIDialog')); },
    "init-gghorselantern": ()=>{ return initFileUIComponent('UIHorseLantern'); },
    "init-ggloadinglayer": ()=>{ return initFileCoreBase('GGResource', initFileUIComponent.bind(()=>{}, 'UILoadingLayer')); },
    "init-ggrocker": ()=>{ return initFileUIComponent('UIRocker'); },
    "init-ggscrollnumber": ()=>{ return callSequence([initFileCoreBase.bind(()=>{}, 'GGNumberFormat'), initFileUIComponent.bind(()=>{}, 'UIScrollNumber')]); },
    "init-ggtabcontrol": ()=>{ return initFileUIComponent('UITabControl'); },
    "init-ggtoast": ()=>{ return initFileCoreBase('GGResource', initFileUIComponent.bind(()=>{}, 'UIToast')); },
    "init-gguieffect": ()=>{ return initFileUIComponent('UIEffect'); },
    "init-gguiswitch": ()=>{ return initFileUIComponent('UISwitch'); },
    "init-ggversionlabel": ()=>{ return initFileUIComponent('UIVersionLabel'); },
    "init-ggwidget": ()=>{ return initFileUIComponent('UIWidget'); },
    "init-ggzindex": ()=>{ return initFileUIComponent('UIZIndex'); },
    // "init-transition-hole": ()=>{ return initFileUITransition('Hole'); },
    "init-file-ggi18n": ()=>{ return importI18n(); },
};

/**
 * @en Hooks triggered after extension loading is complete
 * @zh 扩展加载完成后触发的钩子
 */
export const load = function() { 
    console.log('Editor.Utils:', Editor.Utils);
    console.log('path:', Editor.Project.path);
    console.log('name:', Editor.Project.name);
};

/**
 * @en Hooks triggered after extension uninstallation is complete
 * @zh 扩展卸载完成后触发的钩子
 */
export const unload = function() { };
